package com.ruoyi.web.controller.business;

import java.util.Arrays;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BizChatCoupons;
import com.ruoyi.business.service.IBizChatCouponsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * chat优惠券Controller
 *
 * @author lxy
 * @date 2024-04-22
 */
@Api(value = "chat优惠券", tags = {"chat优惠券模块"})
@RestController
@RequestMapping("/business/bizChatCoupons")
public class BizChatCouponsController extends BaseController{

    @Resource
    private IBizChatCouponsService bizChatCouponsService;


    @ApiOperation("查询chat优惠券列表")
    @PreAuthorize("@ss.hasPermi('business:bizChatCoupons:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizChatCoupons bizChatCoupons) {
        startPage();
        List<BizChatCoupons> list = bizChatCouponsService.queryList(bizChatCoupons);
        return getDataTable(list);
    }

    @ApiOperation("导出chat优惠券")
    @PreAuthorize("@ss.hasPermi('business:bizChatCoupons:export')")
    @Log(title = "chat优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizChatCoupons bizChatCoupons) {
        List<BizChatCoupons> list = bizChatCouponsService.queryList(bizChatCoupons);
        ExcelUtil<BizChatCoupons> util = new ExcelUtil<BizChatCoupons>(BizChatCoupons.class);
        util.exportExcel(response, list, "chat优惠券数据");
    }

    @ApiOperation("获取chat优惠券详细信息")
    @PreAuthorize("@ss.hasPermi('business:bizChatCoupons:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(bizChatCouponsService.getById(id));
    }

    @ApiOperation("新增chat优惠券")
    @PreAuthorize("@ss.hasPermi('business:bizChatCoupons:add')")
    @Log(title = "chat优惠券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizChatCoupons bizChatCoupons) {
        return toAjax(bizChatCouponsService.save(bizChatCoupons));
    }

    @ApiOperation("修改chat优惠券")
    @PreAuthorize("@ss.hasPermi('business:bizChatCoupons:edit')")
    @Log(title = "chat优惠券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizChatCoupons bizChatCoupons) {
        return toAjax(bizChatCouponsService.updateById(bizChatCoupons));
    }

    @ApiOperation("删除chat优惠券")
    @PreAuthorize("@ss.hasPermi('business:bizChatCoupons:remove')")
    @Log(title = "chat优惠券", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(bizChatCouponsService.removeByIds(Arrays.asList(ids)));
    }

    //     --------------------------------------------------------
}
